What is the Priority Queue in Data Structure? | Data Structure Tutorial
In this article, you will learn about this:
- What is the Priority Queue?
- What is the difference between Priority Queue and Normal Queue?
- Working on Priority Queue
- Priority Queue Applications
What is the Priority Queue?
A priority queue is a unique type of queue in which each element is associated with a value of priority. Elements are served based on their priority. That is, items with a higher priority are served first. If the elements have the same priority, they are served according to their order in the queue.
Assigning Priority Value:
Generally, the value of the item is considered for giving priority. The element having the highest value is considered the highest priority element. However, in different cases, we assume that the element having the lowest value is the highest priority element.
Difference Between Priority Queue and Normal Queue
In the normal queue, the First In First Out (FIFO) approach is implemented whereas, in a priority value, the values that have the highest value are removed first. The elements are removed based on priority.
Working on Priority Queue
The basic Operations of the priority queue are appending, removing, and peeking elements.
Adding an element to the priority queue
- Inserting an item at the end of the tree.
- Heapify the tree.
Deleting an item from the priority queue
- Select the item to be deleted.
- Swap the element with the last element.
- Delete the last element.
- Heapify the Tree.
Peeking from the Priority Queue
It returns the maximum value element from the Max Heap and the minimum value element from the Min Heap without deleting the node.
Extract Max/Min from the Priority Queue
Extract - Max gives the node with maximum value only after returning it from a Max Heap whereas Extract - Min gives the node with minimum value only after removing it from the Min Heap.
Applications of Priority Queue:
- Implementing stack
- Data compression in Huffman code
- Load balancing and interrupt handling in an operating system
- Dijkstra’s Algorithm


